package cn.wolfcode.rbac.web.controller;

import cn.wolfcode.rbac.domain.Department;
import cn.wolfcode.rbac.domain.SystemDictionary;
import cn.wolfcode.rbac.query.QueryObject;
import cn.wolfcode.rbac.service.IDpartementService;
import cn.wolfcode.rbac.service.ISystemDictionaryService;
import cn.wolfcode.rbac.util.JsonResult;
import cn.wolfcode.rbac.util.RequriedPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/systemDictionary")
public class SystemDictionaryController {
    @Autowired
    private ISystemDictionaryService systemDictionaryService;

    //@RequriedPermission(name="部门页面", expression="department:list")
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model){
       PageInfo pageInfo = this.systemDictionaryService.query(qo);
       model.addAttribute("result",pageInfo);
        return "systemDictionary/list";
    }

  
    //@RequriedPermission(name="部门新增/编辑", expression="department:saveOrUpdate")
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(SystemDictionary entity){
        try{
            if(entity.getId() == null){
                this.systemDictionaryService.saveOrUpdate(entity);
            }else{
                this.systemDictionaryService.saveOrUpdate(entity);
            }
            return new JsonResult("操作成功", true);
        }catch (Exception e){
            e.printStackTrace();
            return new JsonResult("操作失败", false);
        }
    }

}
